package cn.webrx.bs.servlet;

import cn.webrx.bs.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * <p>功能描述: </p>
 *
 * @author webrx
 * @version 1.0
 * @date 2020-08-25 11:44
 */
@WebServlet("/my")
public class My  extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("flag",true);
        req.setAttribute("now",new Date());
        req.setAttribute("money",1008.24);
        req.setAttribute("str","java freemarker");
        req.setAttribute("langs",new String[]{"java","php","python"});
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("id",10);
        map.put("name","李四");
        map.put("birth",new Date());
        map.put("age",18);
        list.add(map);
        req.setAttribute("map",map);
        req.setAttribute("list",list);
        List<Student> stus = new ArrayList<>();
        stus.add(new Student(1,"李四",80));
        stus.add(new Student(3,"王五",20));
        stus.add(new Student(2,"李丽",30));
        stus.add(new Student(9,"赵六",10));
        req.setAttribute("stus",stus);
        req.getRequestDispatcher("my.ftl").forward(req, resp);
    }
}
